import { useEffect } from "react";
import { useLocation, useNavigate } from "react-router-dom";

const useAuth = () => {
    const token = localStorage.getItem('token');
    const nav = useNavigate();
    const { pathname } = useLocation()
    const whitelist = ['/layout/user/userList']

    useEffect(() => {
        if(!token && !whitelist.includes(pathname)) {
            nav('/login');
        }
    })
}

export default useAuth;